Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug(fix): PhoneNumberField does not honor readonly prop #1878

Merged
merged 4 commits into from
May 13, 2022

Conversation

joebuono
Copy link
Contributor

@joebuono joebuono commented May 11, 2022

Description of changes

This PR address this issue: "PhoneNumberField dial code dropdown doesn't honor readonly prop"

As a result of these changes, if the isReadOnly prop is passed to the PhoneNumberField:

  • The CountryCodeSelect primitive is marked with the aria-disabled=“true” attribute. The reason we’re not marking it with aria-readonly=“true” is because that does not cause screen readers to announce anything to customers. @hbuchel
  • All the options in the CountryCodeSelect are marked with the disabled attribute because the select field should still be readable and focusable, but disallow changing the readonly selection.
  • Form data is still submitted if the isReadOnly prop is passed.

readonlygif

Issue #, if available

Fixes #1795

Description of how you validated changes

Ran the docs locally and wrote some unit tests.

Checklist

  • PR description included
  • yarn test passes
  • Tests are updated
  • No side effects or sideEffects field updated

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@changeset-bot
Copy link

changeset-bot bot commented May 11, 2022

🦋 Changeset detected

Latest commit: bd13a85

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@aws-amplify/ui-react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@joebuono joebuono temporarily deployed to ci May 11, 2022 21:36 Inactive
@joebuono joebuono temporarily deployed to ci May 11, 2022 21:36 Inactive
@joebuono joebuono temporarily deployed to ci May 11, 2022 21:36 Inactive
@joebuono joebuono temporarily deployed to ci May 11, 2022 21:36 Inactive
Copy link
Contributor

@jacoblogan jacoblogan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

const dialList = dialCodeList ?? countryDialCodes;
const countryCodeOptions = React.useMemo(
() =>
dialList.map((dialCode) => (
<option key={dialCode} value={dialCode}>
<option key={dialCode} value={dialCode} disabled={isReadOnly}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a comment of why we are mapping disabled to isReadOnly? We will wonder later on.

);

return (
<SelectField
aria-disabled={isReadOnly}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, I think there should be a comment on why this is more accessible.

@@ -29,6 +31,34 @@ describe('PhoneNumberField primitive', () => {
};
};

const originalLog = console.log;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: put this above the describe, and reassign originalLog in an afterEach.

@@ -135,4 +165,24 @@ describe('PhoneNumberField primitive', () => {

expect(onCountryCodeChange).toHaveBeenCalled();
});

it('should set aria-disabled="true" when the isReadOnly prop is passed, and disable all the select options', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comment on why this behavior exists

Copy link
Contributor

@reesscot reesscot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking great, just had some comments. Also, the demo is showing a button that looks too tall. Can we fix that?

Copy link
Contributor

@zchenwei zchenwei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Humm, SR wouldn't announce anything from elements marked by aria-readonly=true? It feels weird.

@hbuchel
Copy link
Contributor

hbuchel commented May 12, 2022

Humm, SR wouldn't announce anything from elements marked by aria-readonly=true? It feels weird.

I think it's because select elements don't support the readonly html attribute; it's suggested to use the disabled html attribute, but that has other effects on form data that is submitted (disabled inputs will not have their data submitted).

Note: Only text controls can be made read-only, since for other controls (such as checkboxes and buttons) there is no useful distinction between being read-only and being disabled, so the readonly attribute does not apply.

https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/readonly

@joebuono joebuono temporarily deployed to ci May 12, 2022 17:35 Inactive
@joebuono joebuono temporarily deployed to ci May 12, 2022 17:35 Inactive
@joebuono joebuono temporarily deployed to ci May 12, 2022 17:35 Inactive
@joebuono joebuono temporarily deployed to ci May 12, 2022 17:35 Inactive
@joebuono joebuono merged commit 279dbc8 into main May 13, 2022
@joebuono joebuono deleted the readonly-phoneNumberField branch May 13, 2022 15:53
@github-actions github-actions bot mentioned this pull request May 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: PhoneNumber field dial code dropdown doesn't honor readonly prop
6 participants